package com.fshuqing.learing.spring.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author fshuqing
 */
public class App {
    public static void main(String[] args) {
        String basePackages = "com.fshuqing.learing.spring.bean";
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(basePackages);
        // return bean from AppConfigruation
        System.out.println("createUser = " + context.getBean("createUser"));
        // @Component 中默认返回首字母小写
        System.out.println("user = " + context.getBean("user"));

        // 此时创建了两个user，会报错，@Component和createUser,@Component默认为首字母小写，
        // 和AppConfigruation中newUser返回相同，抛出异常
        User bean;
        try {
            bean = context.getBean("user1", User.class);
            System.out.println("bean = " + bean.getName());
        } catch (BeansException e) {
            e.printStackTrace();
        }

        context.close();
    }
}
